<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
	<th:block th:include="include :: header('发送短息')" />
</head>
<body class="white-bg">
<div class="row  border-bottom white-bg dashboard-header">
	<div class="col-sm-6">
		<h2>发送单条短息测试</h2>
		<div class="wrapper wrapper-content animated fadeInRight ibox-content">
			<form class="form-horizontal m" id="form-smsTemplate-add">
				<div class="form-group">
					<label class="col-sm-3 control-label">模版编码：</label>
					<div class="col-sm-8">
						<input id="smsTemplateCode" name="smsTemplateCode" class="form-control" type="text">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">手机号码：</label>
					<div class="col-sm-8">
						<input id="sendRecordPhone" name="sendRecordPhone" class="form-control" type="text">
					</div>
				</div>
				<div class="form-group">
					<div class="form-control-static col-sm-offset-9">
						<button type="submit" class="btn btn-primary">发送</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="col-sm-6">
		<h2>验证短信验证码：</h2>
		<div class="wrapper wrapper-content animated fadeInRight ibox-content">
			<form class="form-horizontal m" id="form-smsTemplate-verify">
				<input type="hidden" id="msgOrderNo" name="msgOrderNo"/>
				<div class="form-group">
					<label class="col-sm-3 control-label">手机号码：</label>
					<div class="col-sm-8">
						<input id="vphone" name="vphone" class="form-control" type="text">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">短信验证码：</label>
					<div class="col-sm-8">
						<input id="sendRecordVerifyCode" name="sendRecordVerifyCode" class="form-control" type="text">
					</div>
				</div>
				<div class="form-group">
					<div class="form-control-static col-sm-offset-9">
						<button type="button" class="btn btn-primary" onclick="verifyCodeSend();">验证</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<div class="row  border-bottom white-bg dashboard-header">
	<div class="col-sm-6">
		<h2>群发短息测试</h2>
		<div class="wrapper wrapper-content animated fadeInRight ibox-content">
			<form class="form-horizontal m" id="form-smsTemplate-addBatch">
				<div class="form-group">
					<label class="col-sm-3 control-label">模版编码：</label>
					<div class="col-sm-8">
						<input id="smsTemplateCode1" name="smsTemplateCode1" class="form-control" type="text">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">手机号码：</label>
					<div class="col-sm-8">
						<textarea id="sendRecordPhone1" name="sendRecordPhone1" class="form-control" rows="10"></textarea>
					</div>
				</div>
				<div class="form-group">
					<div class="form-control-static col-sm-offset-9">
						<button type="button" class="btn btn-primary" onclick="addBatch();">发送</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "message/smsTemplate"
    $("#form-smsTemplate-add").validate({
        rules:{
            xxxx:{
                required:true,
            }
        },
        submitHandler: function(form) {
            send()
        }
    });


    function send() {
        var smsTemplateCode = $("input[name='smsTemplateCode']").val();
        var sendRecordPhone = $("input[name='sendRecordPhone']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "message/smsTemplate/send",
            data : {
                "smsTemplateCode": smsTemplateCode,
                "sendRecordPhone": sendRecordPhone
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.modal.alertSuccess(data.msg);
                $("input[name='smsTemplateCode']").val("");
                $("input[name='sendRecordPhone']").val("");
                $("input[name='msgOrderNo']").val(data.msgOrderNo);
                $("input[name='vphone']").val(sendRecordPhone);
            }
        });
    };

    function addBatch() {
        var smsTemplateCode = $("input[name='smsTemplateCode1']").val();
        var sendRecordPhone = $("#sendRecordPhone1").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "message/smsTemplate/batchSend",
            data : {
                "smsTemplateCode": smsTemplateCode,
                "sendRecordPhone": sendRecordPhone
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.modal.alertSuccess(data.msg);
                $("input[name='smsTemplateCode1']").val("");
                $("#sendRecordPhone1").val("");
            }
        });
    };

    function verifyCodeSend() {
        var sendRecordVerifyCode = $("input[name='sendRecordVerifyCode']").val();
        var msgOrderNo = $("input[name='msgOrderNo']").val();
        var sendRecordPhone = $("input[name='vphone']").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "message/smsTemplate/verifyCode",
            data : {
                "sendRecordVerifyCode": sendRecordVerifyCode,
                "msgOrderNo": msgOrderNo,
                "sendRecordPhone": sendRecordPhone
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.modal.alertSuccess(data.msg);
                $("input[name='sendRecordVerifyCode']").val("");
                $("input[name='msgOrderNo']").val("");
                $("input[name='vphone']").val("");
            }
        });
    }
</script>
</body>
</html>
